package tgc.rj.zz.controller;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;


import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class MainController {

	@RequestMapping(value="/login",method=RequestMethod.GET)
	public String login(){
		return "login";
		
	}
	
	@RequestMapping(value="/main")
    public String main(HttpServletRequest request) {
        //String path = request.getContextPath() ;
       // String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
        Set<String> roles = AuthorityUtils.authorityListToSet(SecurityContextHolder.getContext().getAuthentication().getAuthorities());
        if(roles.contains("ROLE_USER")) {
            return "welcome";
          }else{
        	return "index";
          }
    }
	@RequestMapping("/newFile")
	public String newFile(){
		return "newFile";
	}
    
}
